package com.example.demo.mapper;

import com.example.demo.pojo.Recharge;
import com.example.demo.pojo.UtilityBill;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UtilityBillMapper {

    @Select("select * from  utilitybill where userid = #{userid}")
    List<UtilityBill> findByuserid(int userid);

    @Select("insert into utilitybill (userid,remainingbalance,createtime,waterusage,watercost,electricityusage,electricitycost,totalamount) values (#{userid},#{remainingbalance},now(),0,0,0,0,0)")
    void add(int userid, double remainingbalance);

    @Update("update utilitybill set waterusage = #{waterusage},watercost=#{watercost},electricityusage=#{electricityusage},electricitycost=#{electricitycost},totalamount=#{totalamount},remainingbalance=#{remainingbalance} where billid=#{billid}")
    void update(double waterusage,double watercost,double electricityusage,double electricitycost,double totalamount,double remainingbalance,int billid);

    @Select("select * from utilitybill where endtime is null and userid=#{userid}")
    UtilityBill selectendnull(int userid);

    @Select("update utilitybill set endtime=now() where billid=#{billid}")
    void setendtime(int billid);

    List<UtilityBill> findByUserid(int userid);

    List<UtilityBill> findByrealname(String realname);

    @Select("select UB.*,U.realname from utilitybill UB JOIN user U ON UB.userid=U.userid where billid=#{billid}")
    UtilityBill getBybillid(Integer billid);

}
